package com.cby.android.sample.utils

import android.text.TextUtils
import java.util.*

object CaiyunUtils {

    private val weatherTextMap: HashMap<String, String> =
        object : HashMap<String, String>() {
            init {
                put("CLEAR_DAY", "晴（白天）")
                put("CLEAR_NIGHT", "晴（夜间）")
                put("PARTLY_CLOUDY_DAY", "多云（白天）")
                put("PARTLY_CLOUDY_NIGHT", "多云（夜间）")
                put("CLOUDY", "阴")
                put("LIGHT_HAZE", "轻度雾霾")
                put("MODERATE_HAZE", "中度雾霾")
                put("HEAVY_HAZE", "重度雾霾")
                put("LIGHT_RAIN", "小雨")
                put("MODERATE_RAIN", "中雨")
                put("HEAVY_RAIN", "大雨")
                put("STORM_RAIN", "暴雨")
                put("FOG", "雾")
                put("LIGHT_SNOW", "小雪")
                put("MODERATE_SNOW", "中雪")
                put("HEAVY_SNOW", "大雪")
                put("STORM_SNOW", "暴雪")
                put("DUST", "浮尘")
                put("SAND", "沙尘")
                put("WIND", "大风")
            }
        }

    fun getWeatherText(code: String?): String? {
        var text = weatherTextMap[code]
        if (TextUtils.isEmpty(text)) {
            text = "未知"
        }
        return text
    }


    fun getWindScale(speed: Double): Int {
        var scale = 0
        if (speed < 1) {
            scale = 0
        } else if (speed in 1.0..5.0) {
            scale = 1
        } else if (speed in 6.0..11.0) {
            scale = 2
        } else if (speed in 12.0..19.0) {
            scale = 3
        } else if (speed in 20.0..28.0) {
            scale = 4
        } else if (speed in 29.0..38.0) {
            scale = 5
        } else if (speed in 39.0..49.0) {
            scale = 6
        } else if (speed in 50.0..61.0) {
            scale = 7
        } else if (speed in 62.0..74.0) {
            scale = 8
        } else if (speed in 75.0..88.0) {
            scale = 9
        } else if (speed in 89.0..102.0) {
            scale = 10
        } else if (speed in 103.0..117.0) {
            scale = 11
        } else if (speed in 118.0..133.0) {
            scale = 12
        } else if (speed in 134.0..149.0) {
            scale = 13
        } else if (speed in 150.0..166.0) {
            scale = 14
        } else if (speed in 167.0..183.0) {
            scale = 15
        } else if (speed in 184.0..201.0) {
            scale = 16
        } else if (speed in 202.0..220.0) {
            scale = 17
        }
        return scale
    }


    fun getWindDirection(direction: Double): String? {
        var result = ""
        if (direction >= 348.76 || direction <= 11.25) {
            result = "北"
        } else if (direction in 11.26..33.75) {
            result = "北东北"
        } else if (direction in 33.76..56.25) {
            result = "东北"
        } else if (direction in 56.26..78.75) {
            result = "东东北"
        } else if (direction in 78.76..101.25) {
            result = "东"
        } else if (direction in 101.26..123.75) {
            result = "东东南"
        } else if (direction in 123.76..146.25) {
            result = "东南"
        } else if (direction in 146.26..168.75) {
            result = "南东南"
        } else if (direction in 168.76..191.25) {
            result = "南"
        } else if (direction in 191.26..213.75) {
            result = "南西南"
        } else if (direction in 213.76..236.25) {
            result = "西南"
        } else if (direction in 236.26..258.75) {
            result = "西西南"
        } else if (direction in 258.76..281.25) {
            result = "西"
        } else if (direction in 281.26..303.75) {
            result = "西西北"
        } else if (direction in 303.76..326.25) {
            result = "西北"
        } else if (direction in 326.26..348.75) {
            result = "北西北"
        }
        return result
    }
}